// Copyright 2021 Guoyoko. All Rights Reserved.

#include "Slate/SSWPropertyBoolWidget.h"
#include "Widgets/Input/SCheckBox.h"


void SSWPropertyBoolWidget::Construct(const FArguments& InArgs, FSWBaseProperty* InBaseProperty)
{
	SSWPropertyRowBaseWidget::Construct(SSWPropertyRowBaseWidget::FArguments().NodeName(InArgs._NodeName), InBaseProperty); 

	TSharedRef<SBox> PropertyLeftRow =
		SNew(SBox)
		[
			SNew(STextBlock)
			.Text(FText::FromName(NodeName))
		];

	TSharedRef<SBox> PropertyRightRow =
		SNew(SBox)
		[
			SNew(SCheckBox)
			.IsChecked(ECheckBoxState::Checked)
			.OnCheckStateChanged(this, &SSWPropertyBoolWidget::OnCheckedInitialCommit)
		];


	ChildSlot
	[
		SNew(SHorizontalBox)
			+ SHorizontalBox::Slot()
			[
				PropertyLeftRow
			]
			+ SHorizontalBox::Slot()
			[
				PropertyRightRow
			]
	];
}

void SSWPropertyBoolWidget::OnCheckedInitialCommit(ECheckBoxState NewCheckedState)
{
	if (BaseProperty->SelectedActor != nullptr)
	{
		if (NewCheckedState == ECheckBoxState::Checked)
		{
			BaseProperty->SelectedActor->SetActorHiddenInGame(false);
		}
		if (NewCheckedState == ECheckBoxState::Unchecked)
		{
			BaseProperty->SelectedActor->SetActorHiddenInGame(true);
		}
	}
}

